package com.ruoyi.server.api.imgactivity.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.server.api.imgactivity.domain.ImgActivity;
import com.ruoyi.server.api.imgactivity.service.IImgActivityService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 活动图片Controller
 * 
 * @author ruoyi
 * @date 2024-12-02
 */
@RestController
@RequestMapping("/activity/activity")
public class ImgActivityController extends BaseController
{
    @Autowired
    private IImgActivityService imgActivityService;

    /**
     * 查询活动图片列表
     */
    @PreAuthorize("@ss.hasPermi('activity:activity:list')")
    @GetMapping("/list")
    public TableDataInfo list(ImgActivity imgActivity)
    {
        startPage();
        List<ImgActivity> list = imgActivityService.selectImgActivityList(imgActivity);
        return getDataTable(list);
    }

    /**
     * 导出活动图片列表
     */
    @PreAuthorize("@ss.hasPermi('activity:activity:export')")
    @Log(title = "活动图片", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ImgActivity imgActivity)
    {
        List<ImgActivity> list = imgActivityService.selectImgActivityList(imgActivity);
        ExcelUtil<ImgActivity> util = new ExcelUtil<ImgActivity>(ImgActivity.class);
        util.exportExcel(response, list, "活动图片数据");
    }

    /**
     * 获取活动图片详细信息
     */
    @PreAuthorize("@ss.hasPermi('activity:activity:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(imgActivityService.selectImgActivityById(id));
    }

    /**
     * 新增活动图片
     */
    @PreAuthorize("@ss.hasPermi('activity:activity:add')")
    @Log(title = "活动图片", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ImgActivity imgActivity)
    {
        return toAjax(imgActivityService.insertImgActivity(imgActivity));
    }

    /**
     * 修改活动图片
     */
    @PreAuthorize("@ss.hasPermi('activity:activity:edit')")
    @Log(title = "活动图片", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ImgActivity imgActivity)
    {
        return toAjax(imgActivityService.updateImgActivity(imgActivity));
    }

    /**
     * 删除活动图片
     */
    @PreAuthorize("@ss.hasPermi('activity:activity:remove')")
    @Log(title = "活动图片", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(imgActivityService.deleteImgActivityByIds(ids));
    }

    /**
    * @Author zsc
    * @Description 查询获得列表
    * @Date 2024/12/2 15:02
    * @Return com.ruoyi.common.core.domain.AjaxResult

    */

    @GetMapping("/ArticleLater")
    public AjaxResult ArticleLater(String searchQuery)
    {

        List<ImgActivity> list = imgActivityService.ArticleLater(searchQuery);

        return success(list);

    }
}
